package com.github.icloudpay.pay.core.biz;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.icloudpay.pay.core.entity.PayChannelConfig;
import com.github.icloudpay.pay.core.mapper.PayChannelConfigMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;

import lombok.extern.slf4j.Slf4j;

/**
 * 支付通道配置表
 *
 * @author hexufeng
 * @email lfw6699@163.com
 * @date 2018-06-05 14:17:16
 */
@Slf4j
@Service
public class PayChannelConfigBiz extends BaseBiz<PayChannelConfigMapper,PayChannelConfig> {
	
	@Autowired
	private PayChannelConfigMapper payChannelConfigMapper;
	
	/**
	 * 查询支付通道
	 * 先根据商户号和支付通道参数查询，若为空，再根据平台编号查询支付通道
	 * @param request
	 * @return
	 */
	public PayChannelConfig getPayChannelConfig(PayChannelConfig request){
		
		//根据商户号和支付通道参数查询
		PayChannelConfig payChannelConfigBymer = new PayChannelConfig();
		payChannelConfigBymer.setPayCompanyNo(request.getPayCompanyNo());
		payChannelConfigBymer.setPayChannelNo(request.getPayChannelNo());
		payChannelConfigBymer.setMerId(request.getMerId());
		PayChannelConfig selectOneBymer = payChannelConfigMapper.selectOne(payChannelConfigBymer);
		if(null == selectOneBymer){
			//根据平台编号和支付通道参数查询
			PayChannelConfig payChannelConfigByplat = new PayChannelConfig();
			payChannelConfigByplat.setPayCompanyNo(request.getPayCompanyNo());
			payChannelConfigByplat.setPayChannelNo(request.getPayChannelNo());
			payChannelConfigByplat.setPlatformId(request.getPlatformId());
			PayChannelConfig selectOneByplat = payChannelConfigMapper.selectOne(payChannelConfigBymer);
			return selectOneByplat;
		}else{
			return selectOneBymer;
		}
	}
	
	
	/**
	 * 查询支付通道配置
	 * @param map
	 * @return
	 */
	public List<PayChannelConfig> queryPayChannelConfig(Map<String, Object> map) {
		log.info("查询支付通道配置，参数。。。{}"+map);
		return payChannelConfigMapper.queryPayChannelConfig(map);
	}
}